package com.woniu.account.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniu.account.dto.ResourceDto;
import com.woniu.account.form.ResourceInsertForm;
import com.woniu.account.model.TResource;
import com.woniu.account.service.TResourceService;
import com.woniu.core.util.JwtUtil;
import com.woniu.core.util.RedisUtil;
import com.woniu.core.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 吴彦祖
 * @since 2024年04月02日
 */
@RestController
@RequestMapping("/tResource")
@Api(tags = "资源表相关接口")
public class TResourceController {
    @Resource
    private TResourceService tresourceService;
    @Resource
    private RedisUtil redisUtil;
    //根据管理员id查询该管理员拥有的所有1级和2级菜单
    @GetMapping("/findMenu")
//    @RequiredRole(role = {"超级管理员","普通管理员","团队负责人"})
    @ApiOperation("查询一二级权限菜单")
    public Result findMenu()throws Exception{
        Integer userId = JwtUtil.getUserId(1);
        List<ResourceDto> list = tresourceService.selectMenu(userId);
        return Result.getListResult(ResourceDto.class).setMsg("查询成功").setData(list);
    }
    //查询三级权限按钮
    @GetMapping("/findButton")
//    @RequiredRole(role = {"超级管理员","普通管理员","团队负责人"})
    @ApiOperation("查询三级权限按钮")
    public Result findButton()throws Exception{
        Integer userId = JwtUtil.getUserId(1);
        List<ResourceDto> list = tresourceService.findButton(userId);
        return Result.getListResult(ResourceDto.class).setMsg("查询成功").setData(list);
    }

    @GetMapping("list")
    @ApiOperation("查询资源列表")
//    @RequiredRole(role = {"超级管理员","普通管理员","团队负责人"})
    public Result search() throws Exception {
        List<ResourceDto> list = tresourceService.search();
        return Result.getListResult(ResourceDto.class).setMsg("查询成功").setData(list);
    }
    @PostMapping("/insert")
    @ApiOperation("新增资源")
//    @RequiredRole(role = {"超级管理员","普通管理员","团队负责人"})
    public Result insert(@Valid @RequestBody ResourceInsertForm form)throws Exception{
        TResource tResource=tresourceService.insert(form);
        return Result.getResult(TResource.class).setMsg("查询成功").setData(tResource);
    }
}

